<template>
  <!--印章变更列表-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="编号">
              <a-input placeholder="请输入编号" v-model="queryParam.sealQualificationId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类别">
                <j-dict-select-tag
                  type="list"
                  :sealName.sync="sealName"
                  v-model="queryParam.sealType"
                  dictCode="yzlx_type"
                  placeholder="请选择印章类别"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="申请人">
                <select-user-by-dep :multi="false" v-model="queryParam.handlerId"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="变更类型">
                <j-dict-select-tag placeholder="请选择变更类型" v-model="queryParam.changType" dictCode="change_type"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.bpmStatus" dictCode="bpm_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAddK()" type="primary" icon="plus">作废
      </a-button>
      <a-button
        @click="handleAddB()"
        type="primary"
        icon="plus"
        :disabled="isDisabledAuth('erpSealCertificationChangeRecord:addk')">刻印
      </a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('印章变更管理')"
                :disabled="isDisabledAuth('erpSealCertificationChangeRecord:export')">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpSealCertificationChangeRecord:import')">
          导入
        </a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpSealCertificationChangeRecord:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'120%'}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps: getCheckboxProps}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)"
            type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpSealStatusChange2:edit')"

            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpSealCertificationChangeRecord:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-button
              type="primary"
              size="small"
              @click="startProcess(record)"
              :disabled="isDisabledAuth('erpSealCertificationChangeRecord:startProcess')">发起流程</a-button>
          </template>
          <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
          </template>
          <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpSealCertificationChangeRecord:invalidProcess')">
                作废流程
              </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
          </template>
          <template v-if="record.bpmStatus !== '1'">
            <a-button
              type="primary"
              size="small"
              @click="handleTrack(record)"
              :disabled="isDisabledAuth('erpSealCertificationChangeRecord:viewTrack')">审批进度</a-button>
          </template>
        </span>

      </a-table>
    </div>
    <!--:is-show="is_show"-->
    <erp-seal-certification-change-record-modal
      ref="modalForm"
      @ok="modalFormOk"></erp-seal-certification-change-record-modal>
    <erp-seal-certification-change-record-modal2
      ref="modalForm2"
      @ok="modalFormOk"></erp-seal-certification-change-record-modal2>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpSealCertificationChangeRecordModal from './modules/ErpSealCertificationChangeRecordModal'
import ErpSealCertificationChangeRecordModal2 from './modules/ErpSealCertificationChangeRecordModal2'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
// import { cg } from '@views/modules/online/cgform/auto/common/CgformAutoListMixins.js'
import { postAction } from '@/api/manage'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'

export default {
  name: 'ErpSealCertificationChangeRecordList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpSealCertificationChangeRecordModal,
    ErpSealCertificationChangeRecordModal2,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep
  },
  data() {
    return {
      // returnShow:{},
      is_show: false,
      description: '印章变更管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '编号',
          align: 'center',
          dataIndex: 'sealQualificationId',
          ellipsis: true
        },
        // {
        //     title:'标题',
        //     align:"center",
        //     dataIndex: 'bpmBizTitle',
        //     ellipsis: true
        //   },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
          ellipsis: true
        },
        {
          title: '类别',
          align: 'center',
          dataIndex: 'sealType_dictText',
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          // dataIndex: 'handlerId',
          dataIndex: 'handlerId_dictText',
          ellipsis: true
        },
        {
          title: '申请人部门',
          align: 'center',
          // dataIndex: 'handlerDeptId',
          dataIndex: 'applyDept_dictText',
          ellipsis: true
        },
        {
          title: '变更类型',
          align: 'center',
          dataIndex: 'changType_dictText',
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/administration/seal/erpSealCertificationChangeRecord/list',
        delete: '/api/erp/administration/seal/erpSealCertificationChangeRecord/delete',
        deleteBatch: '/api/erp/administration/seal/erpSealCertificationChangeRecord/deleteBatch',
        exportXlsUrl: '/api/erp/administration/seal/erpSealCertificationChangeRecord/exportXls',
        importExcelUrl: 'administration/seal/erpSealCertificationChangeRecord/importExcel',
        bizCount: '/api/erp/administration/seal/erpSealCertificationChangeRecord/bizCount',
        startProcess: '/api/erpmng/act/process/extActProcess/startMutilProcess'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_seal_certification_change_record_001',
      // formUrl: 'scy/administration/seal/modules/ErpSealCertificationChangeRecordForm',
      formUrl: '/erp/administration/seal/modules/ErpSealCertificationChangeRecordForm',
      formUrlMobile: '/pages/synergy/certificationChangeRecord',
      dictOptions: {},
      superFieldList: []
    }
  },
  watch: {
    $route(to, from) {
      this.loadData();
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    handleAddK: function () {
      this.is_show = true;
      this.$refs.modalForm.add(this.is_show);
      this.$refs.modalForm.title = '作废';
      this.$refs.modalForm.disableSubmit = false;
    },
    handleAddB() {
      this.is_show = true;
      this.$refs.modalForm2.add(this.is_show);
      this.$refs.modalForm2.title = '刻印';
      this.$refs.modalForm2.disableSubmit = false;
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'sealQualificationId', text: '编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealType', text: '类别', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerId', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '申请人部门', dictCode: '' })
      fieldList.push({ type: 'int', value: 'changType', text: '变更类型', dictCode: 'change_type' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: 'bpm_status' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'handlerDeptCode', text: '申请人部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealCompany', text: '印章所属公司', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealCertificationHead', text: '印章负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'authorizedPerson', text: '授权责任人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delegate', text: '委托方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'trustee', text: '被委托方（印章保管人）', dictCode: '' })
      fieldList.push({ type: 'date', value: 'entrustDateStart', text: '委托开始时间' })
      fieldList.push({ type: 'date', value: 'entrustDateEnd', text: '委托结束时间' })
      fieldList.push({ type: 'string', value: 'sealCertificationUseScope', text: '印章使用范围', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attentionMatters', text: '注意事项', dictCode: '' })
      fieldList.push({ type: 'string', value: 'upload', text: '上传附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmBizTitle', text: '标题', dictCode: '' })
      this.superFieldList = fieldList
    },
    startProcess(record) {
      if (record.isImpower == 0) {
        this.$confirm({
          title: '提示',
          content: '确认提交流程吗?',
          onOk: () => {
            postAction(this.url.startProcess, {
              id: record.id,
              flowCode: 'erp_seal_certification_change_record_0',
              // formUrl: 'scy/administration/seal/modules/ErpSealCertificationChangeRecordForm',
              formUrl: '/erp/administration/seal/modules/ErpSealCertificationChangeRecordForm',
              formUrlMobile: this.formUrlMobile
            }).then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.loadData()
                this.onClearSelected()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        })
      }
      if (record.isImpower == 1) {
        this.$confirm({
          title: '提示',
          content: '确认提交流程吗?',
          onOk: () => {
            postAction(this.url.startProcess, {
              id: record.id,
              flowCode: this.flowCode,
              formUrl: '/erp/administration/seal/modules/ErpSealCertificationChangeRecordForm',
              formUrlMobile: this.formUrlMobile
            }).then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.loadData()
                this.onClearSelected()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        })
      }
    },
    handleTrack(record) {
      if (record.isImpower == 0) {
        let params = { flowCode: 'erp_seal_certification_change_record_0', dataId: record.id };// 查询条件
        this.$refs.bpmProcessTrackModal.handleTrack(params);
        this.$refs.bpmProcessTrackModal.title = '审批跟踪记录';
      }
      if (record.isImpower == 1) {
        let params = { flowCode: this.flowCode, dataId: record.id };// 查询条件
        this.$refs.bpmProcessTrackModal.handleTrack(params);
        this.$refs.bpmProcessTrackModal.title = '审批跟踪记录';
      }
    },
    // 流程审批结束禁用
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.bpmStatus !== '1'
        }
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
